<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<c:set var="jpath" value="${pageContext.request.contextPath }"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="${jpath}/static/qd/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="${jpath}/static/qd/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="${jpath}/static/qd/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="${jpath}/static/qd/css/cpsc.css"/>

<title>产品上传</title>
</head>

<body>
        <div class="container">
        	<input id="apprpId" type="hidden" value=""/>
			<div class="row">
				  <div class="col-xs-4">
					<a href="javascript:void(0);" onclick="history.go(-1)"><img src="${jpath}/static/qd/img/back.png" height="20" width="20"/></a>
				  </div>
				  <div class="col-xs-8" id="title_text">产品上传</div>
			</div>
        </div>
		
		<div class="content">
			<form id="stuForm" method="post">
			<div class="container">
				<div class="row">
					<div class="col-xs-1" id="org_col_img">丨</div>
					<div class="col-xs-4" id="hui_col_b">产品简介</div>
					<div class="col-xs-7"></div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">产品名称:</div>
					<div class="col-xs-8">
						<input id="title" name="title" class="input" type="text"  placeholder="请输入产品名称"/>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">产品金额:</div>
					<div class="col-xs-8">
						<input id="money" name="money" class="input" type="text"  placeholder="请输入产品金额"/>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">办理条件:</div>
					<div class="col-xs-8">
						<textarea id="conditionP" name="conditionP" class="input" rows="6" style="resize:none;" placeholder="请输入办理条件"></textarea>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">办理流程:</div>
					<div class="col-xs-8">
						<textarea id="processP" name="processP" class="input" rows="6" style="resize:none;" placeholder="请输入办理流程"></textarea>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">办理简介:</div>
					<div class="col-xs-8">
						<textarea id="synopsis" name="synopsis" class="input" rows="6" style="resize:none;" placeholder="请输入办理简介"></textarea>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-1" id="org_col_img">丨</div>
					<div class="col-xs-3" id="hui_col_b">关于我们</div>
					<div class="col-xs-7"></div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">公司规模:</div>
					<div class="col-xs-8">
						<input id="companySize" name="companySize" class="input" type="text"  placeholder="请输入公司规模"/>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">金融机构:</div>
					<div class="col-xs-8">
						<input id="institution" name="institution" class="input" type="text"  placeholder="请输入金融机构"/>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">融资周期:</div>
					<div class="col-xs-8">
						<input id="cycle" name="cycle" class="input" type="text"  placeholder="请输入融资周期"/>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">联系部门:</div>
					<div class="col-xs-8">
						<input id="contactDepartment" name="contactDepartment" class="input" type="text"  placeholder="请输入联系部门"/>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">联系电话:</div>
					<div class="col-xs-8">
						<input class="input" id="contactUs" name="contactUs" type="text"  placeholder="请输入联系电话"/>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">发布时间:</div>
					<div class="col-xs-8">
						<input id="time" name="time" class="input" type="text"  placeholder="请输入发布时间"/>
					</div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-1" id="org_col_img">丨</div>
					<div class="col-xs-3" id="hui_col_b">图片上传</div>
					<div class="col-xs-7"></div>
				</div>
			</div>
			<div class="container">
				<div class="row">
					<div class="col-xs-4" id="org_col_text">上传图片:</div>
					<div class="col-xs-8"></div>
				</div>
			</div>
			<div class="container">
				<div class="col-xs-4"></div>
                <div class="col-xs-3 upload_div" id="addPic">
						<div class="insert_photo">
							<img src="${jpath}/static/qd/img/jia.png" width="15" height="15" />
						</div>
						<div class="blue_text_photo">添加照片</div>
						<input type="file" id="files_btn" style="display:none;"/>
				</div>
				<input type="hidden" name="publisherSession" id="publisherSession" value="${sessionScope.login.loginAccount}"/>
			</div>
			<div class="container">
				<div class="row" id="submit_mar">
					<div class="col-xs-6">
						<input type="button" id="blue_submit" value="保存预览"/>
					</div>
					<div class="col-xs-6">
						<input type="button" id="orange_submit" value="发布"/>
					</div>
				</div>
			</div>
            </form>
		</div>
		
<%@include file="js.jsp"%>
<script type="text/javascript" >
	function checkPhone(){ 
	    var phone = $("#contactUs").val();
	    if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){ 
	    	$("#a").remove();
	    	$("#submit_mar").append("<div id='a' style='color: red;font-size: 1.2rem;margin-left: 8rem;margin-top: 4rem;'>请输入正确的手机号码</div>");
	        return false; 
	    } 
	}
	$("#orange_submit").click(function(){
		if(checkPhone()==false){
			return;
		};
		var src=$("#base64Img").attr("src");
		var file=$("#files_btn").get(0).files[0];
		var jsonForms = getForm("#stuForm");
		jsonForms.synopsis=$("#synopsis").val();
		jsonForms.processP=$("#processP").val();
		jsonForms.conditionP=$("#conditionP").val();
		$.post("${jpath}/uploadFile",{base64File:src,FirstFileName:file.name},function(data){
			console.log(data);
			var json=$.parseJSON(data);
			$("#apprpId").val(json.apprpId);
			if(json.apprpId!=null){
				$.post("${jpath}/cpsc/insert",jsonForms,function(data){
					console.log(data);
					var json = $.parseJSON(data);
					alert(json.resMsg);
					if(json.resMsg=="添加成功"){
						location.href="${jpath}/qd/index";
					};
				});
			}
			});
		
	});
	    function del(_this) {
	        var _this_img = $(_this);
	        _this_img.parent().remove();
	    }
	    $(function() {
	        var file = $("#files_btn");
	        $("#addPic").click(function() {
	            file[0].click();
	        });
	        file[0].addEventListener('change', function() {
	            var file = this.files[0];
	            var reader = new FileReader();
	            reader.readAsDataURL(file);
	            reader.onload = function(e) {
	                var newUrl = this.result;
	                var img_str = '<div class="col-xs-2 upload_div_photo">';
	                img_str += '<img onclick="del(this)" class="del_btn" src="img/close.png" width="12" height="12" />';
	                img_str += '<img id="base64Img" class="fileImg" width="50px" height="50px" src="' + newUrl + '" />';
	                img_str += '</div>';
	                $("#addPic").after(img_str);
	            };
	        });
	    });
</script>
</body>
</html>
